//! \file backtracer_arm_exidx.h

#include "backtracer.h"
#include "arm_utils.h"

//------------------------------------------------------------------------------

#ifndef _BACKTRACER_ARM_EXIDX_H_
#define _BACKTRACER_ARM_EXIDX_H_

//------------------------------------------------------------------------------

TBGError DefaultBacktraceExidx(func_map *pmap, void *frame_begin,
                               void *curr_addr);

//------------------------------------------------------------------------------

TBGError GenBacktraceExidx(func_map *pmap, void *frame_begin, void *curr_addr, 
                           void *stop_addr, trace_struct *stack_trace,
                           size_t trace_max_size);

//------------------------------------------------------------------------------

typedef struct {
    addr_t regs[ARM_REGISTER_COUNT];
    bool r15_updated;
} unwind_status;

//------------------------------------------------------------------------------

#define CMD_DATA_POP 1
#define CMD_DATA_PUSH 2
#define CMD_REFUSED 3
#define CMD_REG_POP 4
#define CMD_REG_TO_SP 5
#define CMD_FINISH 6
#define CMD_VFP_POP_X 7 
#define CMD_VFP_POP_D 8
#define CMD_WREG_POP 9
#define CMD_WCGR_POP 10
#define CMD_RESERVED 11

//------------------------------------------------------------------------------

typedef struct {
    int command;
    addr_t data;
} arm_exidx_cmd;

//------------------------------------------------------------------------------

TBGError ArmExidxDecode(unwind_status *status, unsigned int *buf, size_t len);
TBGError ArmExidxApplyCmd(unwind_status *status, arm_exidx_cmd cmd);

//------------------------------------------------------------------------------

#endif //_BACKTRACER_ARM_EXIDX_H_
